home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PACKET / CBBS60SO.ZIP / PRTLOG.C < prev   
Text File  |  1987-10-20  |  11KB  |  475 lines

  1.  
  2. /*
  3.  * PRTLOG.C - 10/11/87 - Print a log file. For C BBS V3.5
  4.  */
  5.  
  6. #include <stdio.h>
  7.  
  8. /* Cosmetic C definitions */
  9.  
  10. #define  is    ==
  11. #define  isnt    !=
  12. #define  and    &&
  13. #define  or    ||
  14. #define  not    !
  15. #define  true    1
  16. #define  false    0
  17. #define  match    !strcmp
  18.  
  19. #define  linelen 256
  20.  
  21. FILE    *lfl;
  22. int    lall, isuser;
  23.  
  24. short first    = false;
  25. short wasq    = true;
  26. short aconnect    = false;
  27. long  gate    = 0;
  28. long  logd    = 0;
  29. long  down    = 0;
  30. long  avail    = 0;
  31. long  online    = 0;
  32. long  offline    = 0;
  33. long  idle    = 0;
  34. long  connected = 0;
  35. long  sysop    = 0;
  36. long  fwdcon    = 0;
  37. long  fwddis    = 0;
  38.  
  39. int   ngate    = 0;
  40. int   nup    = 0;
  41. int   ndown    = 0;
  42. int   crash    = 0;
  43. int   links    = 0;
  44. int   nts    = 0;
  45. int   scon    = 0;
  46. int   ucon    = 0;
  47. int   lines    = 0;
  48.  
  49. static char  line[linelen];
  50. static char  call[6];
  51. char  *fst, *lp, typ, fn, sfn;
  52.  
  53. struct t
  54. {
  55.   char year[2];
  56.   char month[2];
  57.   char day[2];
  58.   char time[4];
  59. } con, dis, cur, fir, gat, las, sfwd;
  60.  
  61. int nmsg;
  62. int cbin[31][24];
  63. int fbin[31][24];
  64.  
  65. typedef struct FWD_S
  66. {
  67.   char call[9];
  68.   int  count;
  69.   struct FWD_S *next;
  70. } FWD;
  71.  
  72. FWD *fwdhd = NULL;
  73. FWD *fp;
  74.  
  75. #define softeof '\032'
  76.  
  77. main(argc, argv)
  78. int argc;
  79. char *argv[];
  80. {
  81.   register char ch, *cp;
  82.   int i, j, t, done, infile, nfwd;
  83.   int firstent = true;
  84.  
  85.   if (*argv[1] is '-')
  86.   {
  87.     infile = 2; lall = true;
  88.   }
  89.   else
  90.   {
  91.     infile = 1; lall = false;
  92.   }
  93.  
  94.   if ((lfl = fopen(argv[infile], "r")) is NULL)
  95.   { printf("File not found.\n"); exit(0); }
  96.  
  97.   for (i = 0; i < 31; i++) for (j = 0; j < 24; j++)
  98.     { cbin[i][j] = 0; fbin[i][j] = 0; }
  99.  
  100.   while (fgets(line, linelen, lfl) isnt NULL)
  101.   {
  102.     lp = line;
  103.     typ = *lp++;
  104.     cur.year[0]  = *lp++; cur.year[1]  = *lp++;
  105.     cur.month[0] = *lp++; cur.month[1] = *lp++;
  106.     cur.day[0]     = *lp++; cur.day[1]   = *lp++;
  107.     for (cp = cur.time;  cp < cur.time + 4;)  *cp++ = *lp++;
  108.  
  109.     fn = *lp++;
  110.     sfn = *lp++;
  111.     lp++;
  112.     for (cp = lp; *cp; cp++) if ((*cp is '\r') or (*cp is '\n')) *cp = '\0';
  113.  
  114.     if (firstent)
  115.     {
  116.       con = cur; dis = cur; fir = cur; gat = cur; las = cur; sfwd = cur;
  117.       firstent = false;
  118.     }
  119.  
  120.     if (lall)
  121.     {
  122.       if ((typ is 'C') and (fn isnt 'L')) printf("\n");
  123.       if (first and (typ is 'M') and (fn is 'F'))
  124.     { first=false; printf("\n"); }
  125.       printf("     %2.2s/%2.2s/%2.2s %4.4s ",
  126.       cur.month,cur.day,cur.year,cur.time);
  127.     }
  128.  
  129.     lines++;
  130.     switch(typ)
  131.     {
  132.       case 'C': doconn(); break;
  133.       case 'F': dofile(); break;
  134.       case 'G': dogate(); break;
  135.       case 'M': domsg();  break;
  136.       case 'X': doexit(); break;
  137.       default:
  138. /*      printf("Unknown log item type %c\n", typ); */
  139.      ;
  140.     }
  141.  
  142.     las = cur;
  143.   }
  144.  
  145.   fclose(lfl);
  146.  
  147.   if (lall) printf("\f");
  148.  
  149.   printf("\n     Log for %6.6s      ",call);
  150.   printf("From %2.2s/%2.2s/%2.2s %4.4s ",
  151.     fir.month, fir.day, fir.year, fir.time);
  152.   printf(" To %2.2s/%2.2s/%2.2s %4.4s\n",
  153.     cur.month, cur.day, cur.year, cur.time);
  154.  
  155.   printf("     Data from file %s\n",argv[infile]);
  156.   printf("\n                   Connects vs. Hour vs. Date\n\nDa");
  157.  
  158.   ucon     = prtbin(cbin);
  159.  
  160.   avail  = idle + connected;
  161.   online = avail + sysop;
  162.   logd     = online + down + offline;
  163.   idle    -= fwddis;
  164.  
  165.   printf("\n%8d log items.\n", lines);
  166.   printf("%8ld minutes in log.\n", logd);
  167.   printf("%8ld minutes system down.\n", down);
  168.   printf("%8ld minutes system offline.\n", offline);
  169.  
  170.   cp="minutes system online.";
  171.   printf("%8ld %-30s", online, cp);
  172.   printf(" (%5.1f%% of log time.)\n",100.*((float)online/(float)logd));
  173.  
  174.   cp="minutes by sysop.";
  175.   printf("%8ld %-30s", sysop, cp);
  176.   printf(" (%5.1f%% of online time.)\n",100.*((float)sysop/(float)online));
  177.  
  178.   cp="minutes forwarding.";
  179.   printf("%8ld %-30s", fwdcon + fwddis, cp);
  180.   printf(" (%5.1f%% of online time.)\n",100.*((float)(fwdcon + fwddis)/(float)online));
  181.  
  182.   cp="minutes system available.";
  183.   printf("%8ld %-30s", avail, cp);
  184.   printf(" (%5.1f%% of online time.)\n",100.*((float)avail/(float)online));
  185.  
  186.   cp="minutes by users.";
  187.   printf("%8ld %-30s", connected, cp);
  188.   printf(" (%5.1f%% of available time.)\n",100.*((float)connected/(float)avail));
  189.  
  190.   cp="minutes system idle.";
  191.   printf("%8ld %-30s", idle, cp);
  192.   printf(" (%5.1f%% of available time.)\n",100.*((float)idle/(float)avail));
  193.  
  194.   cp="minutes GateWay in use.";
  195.   printf("%8ld %-30s",gate,cp);
  196.   printf(" (%5.1f%% of available time.)\n",100.*((float)gate/(float)avail));
  197.  
  198.   printf("\n%8d connects, %d were links.\n",ucon,links);
  199.   printf("%8d times used by sysop. GateWay used %d times.\n",
  200.   scon,ngate);
  201.   printf("\n%8d File uploads, %d File downloads.\n", nup, ndown);
  202.  
  203.   printf("%8d probable system crashes.\n",crash);
  204.  
  205.   printf("\f\n                   Forwards vs. Hour vs. Date\n\nDa");
  206.  
  207.   nfwd=prtbin(fbin);
  208.  
  209.   printf("\n%8d Messages entered.\n\n", nmsg);
  210.   printf("%8d NTS Messages       (%5.1f%% of messages entered)\n\n",
  211.     nts, 100.*((float)nts/(float)nmsg));
  212.   printf("%8d Messages forwarded (%5.1f%% of messages entered)\n\n",
  213.     nfwd,100.*((float)nfwd/(float)nmsg));
  214.  
  215.   for (fp = fwdhd; fp isnt NULL; fp = fp->next)
  216.   {
  217.     printf("%8d To %9.9s",fp->count,fp->call);
  218.     printf(" (%5.1f%% of messages forwarded.)\n",
  219.       100.*((float)fp->count/(float)nfwd));
  220.   }
  221. }
  222.  
  223. prtbin(b)
  224. int   b[31][24];
  225. {
  226.   register int i, j, t, gt;
  227.  
  228.   for (j = 0; j < 24; j++) printf("%3d",j); printf(" Totl\n");
  229.   for (i = 0; i < 31; i++)
  230.   {
  231.     t = 0;
  232.     printf("%2d",i+1);
  233.     for (j = 0; j < 24; j++)
  234.     {
  235.       if (b[i][j]) printf("%3d",b[i][j]); else printf("  .");
  236.       t += b[i][j];
  237.     }
  238.     printf("%5d\n",t);
  239.   }
  240.  
  241.   gt = 0; printf("  ");
  242.   for (j = 0; j < 24; j++)
  243.  
  244.   {
  245.     t = 0; for (i = 0; i < 31; i++) t += b[i][j];
  246.     gt += t; printf("%3d",t);
  247.   }
  248.   printf("%5d\n",gt);
  249.   return gt;
  250. }
  251.  
  252. dogate()
  253. {
  254.   switch(fn)
  255.   {
  256.     case 'E': gate += (long)tdiff(&gat,&cur); break;
  257.     case 'S': ngate++; break;
  258.     default:  ;
  259.   }
  260.   gat = cur;
  261.  
  262.   if (lall) switch(fn)
  263.   {
  264.     case 'A': printf("Attempted connect to %s\n", lp); break;
  265.     case 'C': printf("Connect to %s\n", lp); break;
  266.     case 'E': printf("GateWay End\n"); break;
  267.     case 'M': printf("Monitor Start\n"); break;
  268.     case 'S': printf("GateWay Start\n"); break;
  269.     case 'U': printf("Unproto Start\n"); break;
  270.   }
  271. }
  272.  
  273. dofile()
  274. {
  275.   if (lall) switch(fn)
  276.   {
  277.     case 'D': printf("Download %s\n", lp); break;
  278.     case 'U': printf("Upload %s\n", lp); break;
  279.     case 'W': printf("Directory %s\n", lp); break;
  280.   }
  281.  
  282.   switch(fn)
  283.   {
  284.     case 'D': ndown++; break;
  285.     case 'U': nup++;   break;
  286.   }
  287. }
  288.  
  289. dofwd()
  290. {
  291.   register int i, find;
  292.   register char *cp, *llp;
  293.   char call[9];
  294.  
  295.   ++fbin[i2(cur.day) - 1][i2(cur.time)];
  296.  
  297.   for (llp = lp; *llp isnt ' '; llp++); llp++;
  298.   llp += 2;
  299.   for (cp = call; ((cp < call + 9) and (*llp isnt ' ') and (*llp isnt '\0'));)
  300.     *(cp++) = *(llp++);
  301.   for (;cp < call + 9;) *(cp++)=' ';
  302.  
  303.   find = false;
  304.   for (fp = fwdhd; ((fp isnt NULL) and !find); fp=fp->next)
  305.   {
  306.     find = !strncmp(fp->call, call, 9);
  307.     if (find) ++(fp->count);
  308.   }
  309.  
  310.   if (!find)
  311.   {
  312.     fp = (FWD *)malloc(sizeof(FWD));
  313.     fp->next = fwdhd; fwdhd = fp;
  314.     fp->count = 1; strncpy(fp->call, call, 9);
  315.   }
  316. }
  317.  
  318. /*
  319.  */
  320.  
  321. domsg()
  322. {
  323.   register int etime;
  324.  
  325.   switch(fn)
  326.   {
  327.     case 'F':
  328.       if (sfn is 'S') sfwd = cur;
  329.       else if (sfn is 'E')
  330.       {
  331.     etime = tdiff(&sfwd, &cur);
  332.     if (aconnect) fwdcon += (long)etime; else fwddis += (long)etime;
  333.       }
  334.       else if (sfn isnt 'R') dofwd();
  335.       break;
  336.  
  337.     case 'C':
  338.     case 'M':
  339.     case 'S':
  340.       nmsg++;
  341.       if (sfn is 'T') nts++;
  342.       break;
  343.   }
  344.  
  345.   if (lall) switch(fn)
  346.   {
  347.     case 'C': printf("Copy %s\n", lp); break;
  348.     case 'E': printf("Edit %s\n", lp); break;
  349.     case 'F':
  350.       if (sfn is 'S')
  351.     printf("Begin forwarding\n");
  352.       else if (sfn is 'E')
  353.     printf("End forwarding\n        (Forward for %d minutes)\n", etime);
  354.       else if (sfn is 'R')
  355.     printf("Begin reverse forward %s\n", lp);
  356.       else printf("Forward %s\n", lp);
  357.       break;
  358.     case 'K': printf("Kill %s\n", lp); break;
  359.     case 'L': printf("List %s\n", lp); break;
  360.     case 'M': printf("Make %s\n", lp); break;
  361.     case 'R': printf("Read %s\n", lp); break;
  362.     case 'S': printf("Send %s\n", lp); break;
  363.     default:  printf("%c   %s\n",sfn, lp); break;
  364.   }
  365. }
  366.  
  367. doexit()
  368. {
  369.   int etime;
  370.   char *sp;
  371.  
  372.   aconnect = false;
  373.   first = true;
  374.   wasq = (fn is 'Q');
  375.   dis = cur;
  376.   etime = tdiff(&con, &dis);
  377.   if (isuser) connected += (long)etime; else sysop += (long)etime;
  378.  
  379.   if (lall)
  380.   {
  381.     switch(fn)
  382.     {
  383.       case 'A': sp = "(On Line)"; break;
  384.       case 'B': sp = "(Said Bye)"; break;
  385.       case 'D': sp = "(Disconnect)"; break;
  386.       case 'E': sp = "(Excluded)"; break;
  387.       case 'F': sp = "(Forced by sysop)"; break;
  388.       case 'Q': sp = "(Exit from program)"; break;
  389.       case 'T': sp = "(Timed out)"; break;
  390.     }
  391.     printf("Exit %s\n        (Connected for %d minutes.)\n", sp, etime);
  392.   }
  393. }
  394.  
  395. doconn()
  396. {
  397.   aconnect = true;
  398.   con = cur;
  399.   switch(fn)
  400.   {
  401.     case 'S':
  402.       isuser = false;
  403.       scon++;
  404.       strncpy(call, lp, 6);
  405.       idle += (long)tdiff(&dis, &con);
  406.       break;
  407.  
  408.     case 'I':
  409.       isuser = false;
  410.       scon++;
  411.       if (wasq) offline += (long)tdiff(&dis, &con);
  412.       else
  413.       {
  414.     crash++;
  415.     dis = las;
  416.     wasq = true;
  417.     down += (long)tdiff(&dis, &con);
  418.       }
  419.       break;
  420.  
  421.     case 'L':
  422.       links++;
  423.       break;
  424.  
  425.     default:
  426.       isuser = true;
  427.       ++cbin[i2(cur.day)-1][i2(cur.time)];
  428.       idle += (long)tdiff(&dis, &con);
  429.       break;
  430.   }
  431.  
  432.   if (lall) switch(fn)
  433.   {
  434.     case 'S': printf("From local console (%s)\n", lp); break;
  435.     case 'I': printf("System startup\n"); break;
  436.     case 'L': printf("Linked to %s\n", lp); break;
  437.     default:  printf("Connected on port %c to %s\n",fn, lp); break;
  438.   }
  439.   first = false;
  440. }
  441.  
  442. tdiff(st,et)
  443. struct t *st, *et;
  444. {
  445.   register int i;
  446.  
  447.   i = t4(et->time) - t4(st->time);
  448.   if (i >= 0) return i;
  449.   if ((st->day[0] is et->day[0]) and (st->day[1] is et->day[1])) return 0;
  450.   return i + 1440;
  451. }
  452.  
  453. i4(t)
  454. char *t;
  455. {
  456.   int i, j;
  457.  
  458.   j = 0;
  459.   for (i = 0; (i < 4) and *t and (*t isnt ' '); i++, t++)
  460.     j = (10 * j) + (*t - '0');
  461.   return j;
  462. }
  463.  
  464. t4(t)
  465. char *t;
  466. { return(60 * i2(t) + i2(t + 2)); }
  467.  
  468. i2(t)
  469. char *t;
  470. {
  471.   if (*t is ' ') *t = '0';
  472.   if (*(t+1) is ' ') *(t+1) = '0';
  473.   return(10*(*t - '0') + (*(t+1) - '0'));
  474. }
  475.